package common.concurrency.baeldung.join;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhang hao dong
 * @date 2025-02-28 15:41
 */

public class SampleThread extends Thread {
    private int processingCount = 0;

    public SampleThread(int processingCount) {
        this.processingCount = processingCount;
        System.out.println("Thread Created");
    }

    @Override
    public void run() {
        System.out.println("Thread " + this.getName() + " started");
        while (processingCount > 0) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                System.out.println("Thread " + this.getName() + " interrupted");
            }
            processingCount--;
            System.out.println("Inside Thread " + this.getName() + ", processingCount = " + processingCount);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new SampleThread(1);
        t2.start();
        System.out.println("Invoking join");
        t2.join();
        System.out.println("Returned from join");
        System.out.println("t2.isAlive:"+t2.isAlive());
    }
}
